﻿using System;
using CollegeSim.Domain.Entities;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace CollegeSim.Domain.Test.Entities
{
    // Author: Ryan Redburn
    // Project: CollegeSim
    // Date: 2/18/2014

    [TestClass]
    public class CourseTest
    {
        #region [ PersonID ]

        [TestMethod]
        public void CourseID_DefaultValue_EqualsExpected()
        {
            // Arrange
            var course = new Course();

            // Assert
            Assert.AreEqual(0, course.CourseID);
        }

        #endregion

        #region [ Subject ]

        [TestMethod]
        public void Subject_Empty_ArgumentNullException()
        {
            // arrange
            var assert = false;
            var course = new Course
            {
                Subject = "CIT",
                Number = "190",
                Title = "JavaScript Programming",
                CreditHours = 2,
                ContactHours = 2,
                Online = false,
                Hybrid = false
            };

            try
            {
                // Act
                course.Subject = "";
            }
            catch (ArgumentNullException)
            {
                assert = true;
            }
            finally
            {
                // Assert
                Assert.IsTrue(assert);
            }
        }

        [TestMethod]
        public void Subject_Null_ArgumentNullException()
        {
            // Arrange
            var assert = false;
            var course = new Course
            {
                Subject = "CIT",
                Number = "190",
                Title = "JavaScript Programming",
                CreditHours = 2,
                ContactHours = 2,
                Online = false,
                Hybrid = false
            };

            try
            {
                // Act
                course.Subject = null;
            }
            catch (ArgumentNullException)
            {
                assert = true;
            }
            finally
            {
                // Assert
                Assert.IsTrue(assert);
            }
        }

        [TestMethod]
        public void Subject_BelowLength_ArgumentOutOfRangeException()
        {
            // Arrange
            var assert = false;
            var course = new Course
            {
                Subject = "CIT",
                Number = "190",
                Title = "JavaScript Programming",
                CreditHours = 2,
                ContactHours = 2,
                Online = false,
                Hybrid = false
            };

            try
            {
                // Act
                course.Subject = "ci";
            }
            catch (ArgumentOutOfRangeException)
            {
                assert = true;
            }
            finally
            {
                // Assert
                Assert.IsTrue(assert);
            }
        }

        [TestMethod]
        public void Subject_AboveLength_ArgumentOutOfRangeException()
        {
            var assert = false;
            var course = new Course
            {
                Subject = "CIT",
                Number = "190",
                Title = "JavaScript Programming",
                CreditHours = 2,
                ContactHours = 2,
                Online = false,
                Hybrid = false
            };

            try
            {
                // Act
                course.Subject = "citt";
            }
            catch (ArgumentOutOfRangeException)
            {
                assert = true;
            }
            finally
            {
                // Assert
                Assert.IsTrue(assert);
            }
        }

        [TestMethod]
        public void Subject_Capitalization_LowerToUpper()
        {
            // Arrange
            var course = new Course
            {
                Subject = "CIT",
                Number = "190",
                Title = "JavaScript Programming",
                CreditHours = 2,
                ContactHours = 2,
                Online = false,
                Hybrid = false
            };

            // Act
            course.Subject = "cit";

            // Assert
            Assert.AreEqual("CIT", course.Subject);
        }

        #endregion

        #region [ Number ]

        [TestMethod]
        public void Number_Empty_ArgumentNullException()
        {
            // Arrange
            var assert = false;
            var course = new Course
            {
                Subject = "CIT",
                Number = "190",
                Title = "JavaScript Programming",
                CreditHours = 2,
                ContactHours = 2,
                Online = false,
                Hybrid = false
            };

            try
            {
                // Act
                course.Number = "";
            }
            catch (ArgumentNullException)
            {
                assert = true;
            }
            finally
            {
                // Assert
                Assert.IsTrue(assert);
            }
        }

        [TestMethod]
        public void Number_Null_ArgumentNullException()
        {
            // Arrange
            var assert = false;
            var course = new Course
            {
                Subject = "CIT",
                Number = "190",
                Title = "JavaScript Programming",
                CreditHours = 2,
                ContactHours = 2,
                Online = false,
                Hybrid = false
            };

            try
            {
                // Act
                course.Number = null;
            }
            catch (ArgumentNullException)
            {
                assert = true;
            }
            finally
            {
                // Assert
                Assert.IsTrue(assert);
            }
        }

        [TestMethod]
        public void Number_BelowLength_ArgumentOutOfRangeException()
        {
            // Arrange
            var assert = false;
            var course = new Course
            {
                Subject = "CIT",
                Number = "190",
                Title = "JavaScript Programming",
                CreditHours = 2,
                ContactHours = 2,
                Online = false,
                Hybrid = false
            };

            try
            {
                // Act
                course.Number = "10";
            }
            catch (ArgumentOutOfRangeException)
            {
                assert = true;
            }
            finally
            {
                // Assert
                Assert.IsTrue(assert);
            }
        }

        [TestMethod]
        public void Number_AboveLength_ArgumentOutOfRangeException()
        {
            // Arrange
            var assert = false;
            var course = new Course
            {
                Subject = "CIT",
                Number = "190",
                Title = "JavaScript Programming",
                CreditHours = 2,
                ContactHours = 2,
                Online = false,
                Hybrid = false
            };

            try
            {
                // Act
                course.Number = "1005";
            }
            catch (ArgumentOutOfRangeException)
            {
                assert = true;
            }
            finally
            {
                // Assert
                Assert.IsTrue(assert);
            }
        }

        #endregion

        #region [ Title ]

        [TestMethod]
        public void Title_Empty_ArgumentNullException()
        {
            // Arrange
            var assert = false;
            var course = new Course
            {
                Subject = "CIT",
                Number = "190",
                Title = "JavaScript Programming",
                CreditHours = 2,
                ContactHours = 2,
                Online = false,
                Hybrid = false
            };

            try
            {
                // Act
                course.Title = "";
            }
            catch (ArgumentNullException)
            {
                assert = true;
            }
            finally
            {
                // Assert
                Assert.IsTrue(assert);
            }
        }

        [TestMethod]
        public void Title_Null_ArgumentNullException()
        {
            // Arrange
            var assert = false;
            var course = new Course
            {
                Subject = "CIT",
                Number = "190",
                Title = "JavaScript Programming",
                CreditHours = 2,
                ContactHours = 2,
                Online = false,
                Hybrid = false
            };

            try
            {
                // Act
                course.Title = null;
            }
            catch (ArgumentNullException)
            {
                assert = true;
            }
            finally
            {
                // Assert
                Assert.IsTrue(assert);
            }
        }

        [TestMethod]
        public void Title_AboveLength_ArgumentOutOfRangeException()
        {
            // Arrange
            var assert = false;
            var course = new Course
            {
                Subject = "CIT",
                Number = "190",
                Title = "JavaScript Programming",
                CreditHours = 2,
                ContactHours = 2,
                Online = false,
                Hybrid = false
            };

            try
            {
                // Act
                course.Title = "Title Title Title Title Title Title Title Title Title Title";
            }
            catch (ArgumentOutOfRangeException)
            {
                assert = true;
            }
            finally
            {
                // Assert
                Assert.IsTrue(assert);
            }
        }

        #endregion

        #region [ CreditHours ]

        [TestMethod]
        public void CreditHours_BelowRange_ArgumentOutOfRangeException()
        {
            // Arrange
            var assert = false;
            var course = new Course
            {
                Subject = "CIT",
                Number = "190",
                Title = "JavaScript Programming",
                CreditHours = 2,
                ContactHours = 2,
                Online = false,
                Hybrid = false
            };

            try
            {
                // Act
                course.CreditHours = 0;
            }
            catch (ArgumentOutOfRangeException)
            {
                assert = true;
            }
            finally
            {
                // Arrange
                Assert.IsTrue(assert);
            }
        }

        [TestMethod]
        public void CreditHours_AboveRange_ArgumentOutOfRangeException()
        {
            var assert = false;
            var course = new Course
            {
                Subject = "CIT",
                Number = "190",
                Title = "JavaScript Programming",
                CreditHours = 2,
                ContactHours = 2,
                Online = false,
                Hybrid = false
            };

            try
            {
                // Act
                course.CreditHours = 7;
            }
            catch (ArgumentOutOfRangeException)
            {
                assert = true;
            }
            finally
            {
                // Arrange
                Assert.IsTrue(assert);
            }
        }

        #endregion

        #region [ ContactHours ]

        [TestMethod]
        public void ContactHours_BelowRange_ArgumentOutOfRangeException()
        {
            // Arrange
            var assert = false;
            var course = new Course
            {
                Subject = "CIT",
                Number = "190",
                Title = "JavaScript Programming",
                CreditHours = 2,
                ContactHours = 2,
                Online = false,
                Hybrid = false
            };

            try
            {
                // Act
                course.ContactHours = 0;
            }
            catch (ArgumentOutOfRangeException)
            {
                assert = true;
            }
            finally
            {
                // Assert
                Assert.IsTrue(assert);
            }
        }

        [TestMethod]
        public void ContactHours_AboveRange_ArgumentOutOfRangeException()
        {
            // Arrange
            var assert = false;
            var course = new Course
            {
                Subject = "CIT",
                Number = "190",
                Title = "JavaScript Programming",
                CreditHours = 2,
                ContactHours = 2,
                Online = false,
                Hybrid = false
            };

            try
            {
                // Act
                course.ContactHours = 7;
            }
            catch (ArgumentOutOfRangeException)
            {
                assert = true;
            }
            finally
            {
                // Assert
                Assert.IsTrue(assert);
            }
        }

        #endregion

        #region [ ToString() ]

        [TestMethod]
        public void CourseToString_ManualRepresentation_EqualsReturn()
        {
            // Arrange
            var course = new Course
            {
                Subject = "CIT",
                Number = "190",
                Title = "JavaScript Programming",
                CreditHours = 2,
                ContactHours = 2,
                Online = false,
                Hybrid = false
            };

            // Assert
            Assert.AreEqual(course.CourseID + " - " + course.Subject + course.Number + " - " + course.Title, course.ToString());
        }

        #endregion
    }
}
